package com.example.common.core.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private static int SUCCESS = 1;
    private static int FAILURE = 0;

    private int sysCode;  //如果有系统错误，则具体的错误内容不能展示给用户
    private int code;   //如果有业务错误，则可以展示给用户
    private String message;
    private T data;

    //返回成功
    public static<T> Result<T> success(){
        return new Result(SUCCESS, SUCCESS,"处理成功", null);
    }

    //返回成功
    public static<T> Result<T> success(T data){
        return new Result(SUCCESS, SUCCESS,"处理成功", data);
    }

    //返回成功
    public static<T> Result<T> success(String message, T data){
        return new Result(SUCCESS, SUCCESS,message, data);
    }

    //返回业务失败
    public static<T> Result<T> failure(){
        return new Result(SUCCESS, FAILURE,"业务处理失败", null);
    }

    //返回业务失败
    public static<T> Result<T> failure(String message){
        return new Result(SUCCESS, FAILURE,message, null);
    }

    //返回系统错误
    public static<T> Result<T> sysFailure() {
        return new Result(FAILURE, FAILURE, "系统处理失败", null);
    }

    //返回系统错误
    public static<T> Result<T> sysFailure(String message) {
        return new Result(FAILURE, FAILURE, message, null);
    }

}
